#ifndef SGI_PRIME_HPP
#define SGI_PRIME_HPP

#include <algorithm>
#include <cstddef>

namespace sgi {
/* SGI STL 哈希表扩容专用的 28 个质数 */
inline std::size_t next_prime(std::size_t n) noexcept {
    static constexpr std::size_t prime_list[28] = {
        53, 97, 193, 389, 769,
        1543, 3079, 6151, 12289, 24593,
        49157, 98317, 196613, 393241, 786433,
        1572869, 3145739, 6291469, 12582917, 25165843,
        50331653, 100663319, 201326611, 402653189, 805306457,
        1610612741, 3221225473, 4294967291
    };
    constexpr auto *first = prime_list;
    constexpr auto *last  = prime_list + 28;
    auto *pos = std::lower_bound(first, last, n);
    return pos == last ? *(last - 1) : *pos;
}

/* 测试：当前 long 位数 */
inline int long_bits() noexcept {
    return sizeof(long) * __CHAR_BIT__;
}
} // namespace sgi

#endif // SGI_PRIME_HPP